/* utatpah.p -   Update and display Item Horizon and Item-Site Horizon        */
/* Copyright 1986-2011 QAD Inc., Santa Barbara, CA, USA.                      */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Id:: utatpah.p 2366 2010-11-10 01:47:19Z zzh                           $: */

/* $Revision: 1.3 $    BY: Hitendra PV      DATE: 06/26/06 ECO: *R05T*        */
/*-Revision end---------------------------------------------------------------*/

/*V8:ConvertMode=FullGUIReport                                                */
/* DISPLAY TITLE                                                              */
{us/mf/mfdtitle.i "1+ "}

define variable line  like pt_prod_line no-undo.
define variable line1 like pt_prod_line no-undo.
define variable part  like pt_part no-undo.
define variable part1 like pt_part no-undo.
define variable type  like pt_part_type no-undo.
define variable type1 like pt_part_type no-undo.
define variable abc   like pt_abc no-undo.
define variable abc1  like pt_abc no-undo.
define variable site  like pt_site no-undo.
define variable buyer like pt_buyer.
define variable buyer1 like pt_buyer.
define variable part_group  like pt_group.
define variable part_group1 like pt_group.
define variable pm like pt_pm_code.
define variable pm1 like pt_pm_code.
define variable l_dsgn_group like pt_dsgn_grp  no-undo.
define variable l_dsgn_group1 like pt_dsgn_grp no-undo.
define variable l_promo like pt_promo no-undo.
define variable l_promo1 like pt_promo no-undo.
define variable l_comm_code like pt_comm_code no-undo.
define variable l_comm_code1 like pt_comm_code no-undo.
define variable l_update_yn  like mfc_logical  no-undo.
define variable l_atp_horizon like pt_atp_horizon no-undo.

define buffer b_pt_mstr for pt_mstr.

form
   line           colon 20
   line1          label {us/t0/t001.i} colon 49 skip
   part           colon 20
   part1          label {us/t0/t001.i} colon 49 skip
   type           colon 20
   type1          label {us/t0/t001.i} colon 49 skip
   abc            colon 20
   abc1           label {us/t0/t001.i} colon 49 skip
   part_group     colon 20
   part_group1    label {us/t0/t001.i} colon 49 skip
   l_dsgn_group   colon 20
   l_dsgn_group1  label {us/t0/t001.i} colon 49 skip
   l_promo        colon 20
   l_promo1       label {us/t0/t001.i} colon 49 skip
   l_comm_code    colon 20
   l_comm_code1   label {us/t0/t001.i} colon 49 skip
   pm             colon 20                skip
   buyer          colon 20
   buyer1         label {us/t0/t001.i} colon 49 skip(1)
   site           colon 8
   l_atp_horizon  colon 35
   l_update_yn    colon 55 skip(1)

with frame a side-labels width 80.

/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

/* REPORT BLOCK */

{us/wb/wbrp01.i}
repeat:

   if part1    = hi_char  then part1    = "".
   if line1    = hi_char  then line1    = "".
   if type1    = hi_char  then type1    = "".
   if abc1     = hi_char  then abc1     = "".

   l_atp_horizon = 0.
   l_update_yn   = no.

   if c-application-mode <> 'web' then
      update
         line
         line1
         part
         part1
         type
         type1
         abc
         abc1
         part_group
         part_group1
         l_dsgn_group
         l_dsgn_group1
         l_promo
         l_promo1
         l_comm_code
         l_comm_code1
         pm
         buyer
         buyer1
         site
         l_atp_horizon
         l_update_yn
      with frame a.

   {us/wb/wbrp06.i &command = update
             &fields  = "  line line1 part part1 type type1
                           abc abc1
                          part_group part_group1
                          l_dsgn_group l_dsgn_group1
                          l_promo l_promo1
                          l_comm_code l_comm_code1
                          pm
                          buyer buyer1
                          site l_atp_horizon l_update_yn"
            &frm     = "a"}

   if (c-application-mode <> 'web') or
      (c-application-mode = 'web'   and
      (c-web-request begins 'data'))
   then do:

      bcdparm = "".
      {us/mf/mfquoter.i line   }
      {us/mf/mfquoter.i line1  }
      {us/mf/mfquoter.i part   }
      {us/mf/mfquoter.i part1  }
      {us/mf/mfquoter.i type   }
      {us/mf/mfquoter.i type1  }
      {us/mf/mfquoter.i site   }
      {us/mf/mfquoter.i abc    }
      {us/mf/mfquoter.i abc1   }
      {us/mf/mfquoter.i part_group }
      {us/mf/mfquoter.i part_group1   }
      {us/mf/mfquoter.i l_dsgn_group   }
      {us/mf/mfquoter.i l_dsgn_group1   }
      {us/mf/mfquoter.i l_promo   }
      {us/mf/mfquoter.i l_promo1  }
      {us/mf/mfquoter.i pm   }
      {us/mf/mfquoter.i buyer  }
      {us/mf/mfquoter.i buyer1  }
      {us/mf/mfquoter.i l_atp_horizon }
      {us/mf/mfquoter.i l_update_yn }


      if part1    = "" then part1     = hi_char.
      if line1    = "" then line1     = hi_char.
      if type1    = "" then type1     = hi_char.
      if abc1     = "" then abc1      = hi_char.
   end. /* IF (c-application-mode... */

   /* PRINTER SELECTION */
   /* OUTPUT DESTINATION SELECTION */
   {us/gp/gpselout.i &printType = "printer"
               &printWidth = 132
               &pagedFlag = " "
               &stream = " "
               &appendToFile = " "
               &streamedOutputToTerminal = " "
               &withBatchOption = "yes"
               &displayStatementType = 1
               &withCancelMessage = "yes"
               &pageBottomMargin = 6
               &withEmail = "yes"
               &withWinprint = "yes"
               &defineVariables = "yes"}
   {us/bbi/mfphead.i}



      for each pt_mstr
         where pt_mstr.pt_domain = global_domain
         and  ( pt_prod_line    >= line
            and pt_prod_line    <= line1)
         and  ( pt_part         >= part
            and pt_part         <= part1)
         and  ( pt_part_type    >= type
            and pt_part_type    <= type1)
         and  ( pt_abc          >= abc
            and pt_abc          <= abc1)
         and  ( pt_group        >= part_group
            and pt_group        <= part_group1)
         and  ( pt_dsgn_grp     >= l_dsgn_group
            and pt_dsgn_grp     <= l_dsgn_group1)
         and  ( pt_promo        >= l_promo
            and pt_promo        <= l_promo1)
         and  ( pt_comm_code    >= l_comm_code
            and pt_comm_code    <= l_comm_code1)
         and  ( pt_buyer        >= buyer
            and pt_buyer        <= buyer1)
      no-lock :

             if l_update_yn
                and site <> ""
             then do:

                for first ptp_det
                   where ptp_det.ptp_domain = global_domain
                   and   ptp_part           = pt_part
                   and   ptp_site           = site
                exclusive-lock:
                end. /* FOR FIRST ptp_det */

                if (available ptp_det
                   and ptp_pm_code <> pm
                   and pm          <> "")
                   or (not available ptp_det)
                then
                   next.

                   ptp_atp_horizon = l_atp_horizon.

                if page-size - line-counter < 5
                then
                   page.
                display
                   pt_part
                   pt_desc1
                   ptp_site
                   ptp_atp_horizon
                   with frame s3 down width 132.
                   down with frame s3.

             end. /* IF l_update and site <> "" */

             if not l_update_yn
                and site <> ""
             then do:

                for first ptp_det
                   fields( ptp_domain ptp_part ptp_pm_code
                           ptp_atp_horizon ptp_site)
                   where ptp_det.ptp_domain = global_domain
                   and   ptp_part  = pt_part
                   and  (if site <> ""
                         then
                         ptp_site = site
                         else
                         true)
                no-lock:
                end. /* FOR FIRST ptp_det */

                if (available ptp_det
                   and ptp_pm_code <> pm
                   and pm          <> "")
                   or (not available ptp_det)
                then
                   next.

                if page-size - line-counter < 5
                then
                   page.
                display
                   pt_part
                   pt_desc1
                   ptp_site
                   ptp_atp_horizon
                with frame s4 down width 132.
                down with frame s4.

             end. /* IF NOT l_update_yn AND site <> "" */

             if l_update_yn
                and site =  ""
             then do:

                for first b_pt_mstr
                   where b_pt_mstr.pt_domain = global_domain
                   and   b_pt_mstr.pt_part   = pt_mstr.pt_part
                exclusive-lock:
                end. /* FOR FIRST pt_mstr */

                if (available b_pt_mstr
                   and b_pt_mstr.pt_pm_code <> pm
                   and pm                   <> "")
                   or (not available b_pt_mstr
                   and b_pt_mstr.pt_pm_code  <> pm
                   and pm                    <> "")
                then
                   next.

                b_pt_mstr.pt_atp_horizon = l_atp_horizon.

                if page-size - line-counter < 5
                then
                   page.

                display
                   b_pt_mstr.pt_part
                   b_pt_mstr.pt_desc1
                   b_pt_mstr.pt_atp_horizon
                   with frame s2 down width 132.
                   down with frame s2.

             end. /* IF l_update_yn and site = "" */

             if not l_update_yn
                and site = ""
             then  do:

                if (available pt_mstr
                   and pt_mstr.pt_pm_code <> pm
                   and pm                 <> "")
                   or (not available pt_mstr
                   and pt_mstr.pt_pm_code  <> pm
                   and pm                  <> "")
                then
                   next.

                if page-size - line-counter < 5
                then
                    page.
                display
                   pt_mstr.pt_part                                                                 pt_mstr.pt_desc1
                   pt_mstr.pt_atp_horizon
                with frame s1 down width 132.
                down with frame s1.

             end. /* IF NOT l_update_yn AND site = "" */

      end. /* FOR EACH pt_mstr */

      /* REPORT TRAILER */
      {us/mf/mfrtrail.i}

end. /* REPEAT*/
